package ui.panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.JComboBox;
import javax.swing.JLabel;

import org.apache.log4j.Logger;

import ui.flowManager.expirimentProperties.ExperimentProperties;
import ui.panels.PanelTypes.PanelType;
/**
 * this Panel will let user chose Experiment type and number of games
 * @author alon
 *
 */
public class ExperimentAndGamePanel extends Panel{
	
	Logger log = Logger.getLogger(this.getClass());
	HashMap<String,Integer> model;
	ArrayList<String> numbers;
	/**
	 * reading properties of this panel.
	 * it is experiment types for experiment constructor
	 * @param map
	 */
	public ExperimentAndGamePanel(HashMap<String, String> map){
		super();
		String initString=readFromProps(map.get("initPropsName"));
		String[] values=initString.split(",");
		model=new HashMap<String,Integer>();
		//putting all values in a map for key:value pairs
		for(int i=0;i<values.length;i=i+2 ){
			model.put(values[i], Integer.parseInt(values[i+1]));
		}
		int num=Integer.parseInt(readFromProps(map.get("maxGameNumber")));
		numbers=new ArrayList<String>();
		for(int i=1;i<=num;i++){
			numbers.add(""+i);
		}
	}
	
	@Override
	public PanelType getPanelType() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void show(ExperimentProperties props) {
		//setting names in JComboBox
		JLabel exType=new JLabel("Experiment Type:");
		this.add(exType);
		JComboBox experimentType=new JComboBox(model.keySet().toArray());
		experimentType.setSelectedIndex(0);
		experimentType.addActionListener(new ExperimentActionListener());
		this.add(experimentType);
		JLabel gameNum=new JLabel("Number of Games:");
		this.add(gameNum);
		JComboBox gameNumCombo=new JComboBox(numbers.toArray());
		gameNumCombo.setSelectedIndex(0);
		gameNumCombo.addActionListener(new GameNumActionListener());
		this.add(gameNumCombo);
	}
	
	private class ExperimentActionListener implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			JComboBox cb = (JComboBox)e.getSource();
	        String exName = (String)cb.getSelectedItem();
	        int exType=model.get(exName);
	    }
		
	}
	
	private class GameNumActionListener implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			JComboBox cb = (JComboBox)e.getSource();
	        String exName = (String)cb.getSelectedItem();
	        int exType=Integer.parseInt(exName);
	    }
		
	}
	@Override
	public void setFromPropertiesConfig(HashMap<String, String> map) {
		// TODO Auto-generated method stub
		
	}
	

}
